#ifndef I2C_INTERFACE_HPP
#define I2C_INTERFACE_HPP

#include "driver/i2c_master.h"
#include "driver/gpio.h"

class I2CInterface {
public:
    I2CInterface();
    I2CInterface(i2c_port_t i2c_num, uint32_t scl_pin, uint32_t sda_pin, i2c_mode_t mode);
    ~I2CInterface();

    void init(i2c_port_t i2c_num, uint32_t scl_pin, uint32_t sda_pin, i2c_mode_t mode);
    int32_t write(uint16_t addr, const uint8_t *data, uint32_t length);
    int32_t write(const uint8_t *data, uint32_t length);
    int32_t writeToDevice(uint16_t addr, const void *reg_data, size_t reg_size, const uint8_t *data, uint32_t length);
    int32_t read(uint16_t addr, uint8_t *data, uint32_t length);
    int32_t readFromDevice(uint16_t addr, const void *reg_data, size_t reg_size, uint8_t *data, uint32_t length);
    i2c_port_t getPort() const { return i2c_num; }

private:
    i2c_port_t i2c_num;
    i2c_master_bus_handle_t bus_handle;
};

#endif // I2C_INTERFACE_HPP
